// 优化跟路径
axios.defaults.baseURL= 'http://api-breakingnews-web.itheima.net'
// 拦截器（请求+响应）
// 作业 ：axios 每一次的请求，响应都会经过（执行）拦截器
// 干啥 ：将重复代码写入到拦截器中，提高代码复用性
// 请求
axios.interceptors.request.use(config => {
// Do something before request is sent
// if (config.url.indexOf('/my')){
//   config.headers.Authorization = localStorage.getItem('token')
// }
// 换成字符串的includes 方法来检测
if (config.url.includes('/my')){
  config.headers.Authorization = localStorage.getItem('token')
}
return config;
},error => {
// Do something with request error
return Promise.reject(error);
});
// 响应
axios.interceptors.response.use(response => {
// Do something before response is sent
if(response.data.status === 1 && response.data.message === '身份认证失败！') {
  location.href = '/login.html'
}
return response;
},error => {
// Do something with response error
return Promise.reject(error);
});